#include "http/http_request.hpp"

HTTPRequest::HTTPRequest()
{
  bytes = 0;
  http_req_type = GET;
  protocol_version = " HTTP/1.1";
  data_sent = "";
  server_name = "";
  headers_set = false;
}

void HTTPRequest::set_header(string field, string value)
{
  headers[field] = value;
  headers_set = true;
}

void HTTPRequest::set_data(string data)
{
  data_sent = "";
}

int HTTPRequest::get_request_type()
{
  return http_req_type;
}

string HTTPRequest::get_data()
{
  return data_sent;
}

string HTTPRequest::get_server()
{
  return server_name;
}

string HTTPRequest::get_headers()
{
  map<string, string> ::iterator header;
  string hdrs = "";
  for(header = headers.begin(); header != headers.end(); header++) {
    hdrs += (*header).first + " : " + (*header).second + "\r\n";
  }
  if(protocol_version == " HTTP/1.1") {
    if(headers.find("Host") == headers.end()) {
      hdrs += "host : " + server_name + "\r\n";
    }
  }
  
  return hdrs;
}

string HTTPRequest::get_version() 
{
  return protocol_version;
}

void HTTPRequest::set_server(string ip)
{
  server_name = ip;
}

void HTTPRequest::get_document(string path)
{
  uri_path = path;
}

string HTTPRequest::get_uri_path()
{
  return uri_path;
}
